import 'package:Smart/pages/productor008/project/res/res_url.dart';
import 'package:Smart/pages/productor008/project/widget/gs_blecall_dialog.dart';
import 'package:flutter/material.dart';
//权限申请
import 'package:permission_handler/permission_handler.dart';
//屏幕适配
import 'package:Smart/utils/screen_unit/gs_screen_util.dart';

/// 平台权限检测并申请设置工具类
class GSPermissionUtil {
  /// 检测并申请拨打电话权限
  static Future<bool> requestPhonePermission({BuildContext context}) async {
    //获取当前权限的状态
    var status = await Permission.phone.status;
    //权限通过，true
    if (status == PermissionStatus.granted) {
      return true;
    } else {
      //权限申请被拒绝，再次申请权限
      var status = await Permission.phone.request();
      //再次申请权限通过，true
      if (status == PermissionStatus.granted) {
        return true;
      } else {
        //再次申请权限拒绝，如果context不为空，
        //打开设置页面，开启权限 返回false
        if (context != null) {
          GSBluetoothCallDialog.showCancelAndConfirm(
            context,
            message: Container(
              margin: EdgeInsets.only(left: 22.w,right: 22.w,top:62.w),
              child: Text('您需要打开拨打电话权限，请到设置中开启',style: TextStyle(fontSize: 18.w),),
              ),
            confirmText: "去设置",
            cancelText: '取消',
            imagePath: ResUrl.iconImagePath("蓝牙钥匙.png"),
            showCheckbox: true,
            onConfirm: (value) {
              openAppSettings();
            }
          );
        }
        return false;
      }
    }
  }
}
